﻿package  {
	
	import flash.display.MovieClip;
	import flash.events.Event;
	
	
	public class LockBlock extends Obstacle {
		
		private var unlocked:Boolean = false;
		var _player:Player;
		
		
		public function LockBlock(aX:Number,aY:Number,aWidth:Number,aHeight:Number,aPlayer:Player)
		{
			// constructor code
			super(aX,aY,aWidth,aHeight);
			
			_player = aPlayer;
			this.addEventListener(Event.ADDED_TO_STAGE,onAddedToStage);
			
		}
		
		
		private function onAddedToStage(e:Event){
			if(!unlocked)
			{
				gotoAndStop(0);
			}
			else
			{
				gotoAndStop(2);
			}
		}
		
		
		override public function CollisionCheck(locX:int, locY:int):Boolean{
			//trace("" + hitTestPoint(locX,locY));
			
			if(hitTestPoint(locX,locY))
			{
				if(_player.MyKey == true && !unlocked)
				{
					unlocked = true;
					_player.MyKey = false;
					this.nextFrame();
				}
			}
			
			if(!unlocked)
			{
				return hitTestPoint(locX,locY);
			}
			else
			{
				return false;
			}
			
			
		}

	}
}